package com.sm.honkon.ui.fragment.more

import android.os.Bundle
import au.com.safie.user.app.util.CacheUtil
import com.sm.honkon.R
import com.sm.honkon.app.base.BaseFragment
import com.sm.honkon.app.ext.getTimeFormat
import com.sm.honkon.app.handle.BottomHandle
import com.sm.honkon.databinding.FrgSettingMaintainBinding
import com.sm.honkon.ui.model.MaintainViewModel
import kotlinx.android.synthetic.main.frg_setting_maintain.*
import me.hgj.jetpackmvvm.ext.nav
import java.util.*

class MaintainFragment : BaseFragment<MaintainViewModel, FrgSettingMaintainBinding>() {
    override fun layoutId(): Int = R.layout.frg_setting_maintain

    override fun initView(savedInstanceState: Bundle?) {
        mDatabind.model = mViewModel
        mDatabind.handle = BottomHandle(nav())

        btn_time_start_now.setOnClickListener {
            mViewModel.config.lvxingTimeLong = Calendar.getInstance().timeInMillis
            mViewModel.config.lvxingTime.set(mViewModel.config.lvxingTimeLong.getTimeFormat("yyyy-MM-dd hh:mm"))
        }
        btn_number_max_edit.setOnClickListener {
            mViewModel.config.setMaxUseCount(Integer.valueOf(ed_number_max_text.text.toString()))
        }
        btn_number_total_edit.setOnClickListener {
            mViewModel.config.surUseCount.set(0)
        }
        btn_save.setOnClickListener {
            CacheUtil.setCommonConfig(mViewModel.config)
            nav().navigateUp()
        }

    }


}